﻿@model TestUp.Models.AdminModels.ViewUsersModel

@{
    ViewBag.Title = "Manage Users";
    Layout = "_AdminLayout.cshtml";
}

<h2>Manage Users</h2>

@(Html.Kendo().Grid(Model.Users)
    .Name("usersGrid")
    .Columns(cols =>
        {
            cols.Bound(x => x.UserId).Hidden(true);
            cols.Bound(x=>x.UserName);
            cols.Bound(x=>x.FirstName);
            cols.Bound(x => x.LastName);
            cols.ForeignKey(x => x.GroupId, Model.Groups, "GroupId", "GroupName").Title("Group");
            cols.ForeignKey(x => x.PermissionId, Model.Permissions, "PermissionId", "PermissionName").Title("Permission");
            cols.Command(cmd => cmd.Edit());
            cols.Command(cmd => cmd.Destroy());
        })
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .ToolBar(cmd => cmd.Create())
    .Groupable()
    .DataSource(dataSource => dataSource
        .Server()
        .Model(model =>
            {
                model.Id(x=>x.UserId);
                model.Field(x => x.UserId).Editable(false);
                model.Field(x => x.PermissionId).Editable(false);
            })
        .Create(create => create.Action("CreateUser", "Admin"))
        .Update(update => update.Action("EditUser", "Admin"))
        .Destroy(destroy => destroy.Action("DeleteUser", "Admin"))
        )
      )